<div class="page-header">
	<ul id="table-tab" class="nav nav-tabs" role="tablist">
		<li role="presentation" class="active"><a href="#subject-tab"
			aria-controls="subject-tab" role="tab" data-toggle="tab">专题管理</a>
		</li>
	</ul>
</div>
<div class="tab-content">
	<div id="subject-tab" class="tab-pane active" role="tabpanel">
		<div class="row">
            <!--搜索域-->
            <div class="col-xs-12">
            	<div class="search-area">
            		<form id="table-subject-search" class="form-inline">
                        <div class="form-group">
                            <label for="subject.name">专题名称：</label>
                            <input type="text" class="form-control input-sm" id="subject-name" name="subject.name" value="" placeholder="按名称搜索">
                            <!-- 浏览器bug，当form中存在单个input时，敲击enter键，会导致form提交，更改url。加入下面input解决此bug -->
                            <input style="display: none;"/>
                        </div>
	                    <button id="btn-subject-search" type="button" class="btn btn-info btn-sm no-border">
	                    	<i class="ace-icon fa fa-search bigger-110"></i>查询
	                    </button>
	                    <div class="form-group pull-right">
                    		<span>查询方式：</span>
                           	<label class="radio-inline">
                           		<input type="radio" name="searchType" value="1" checked="checked"/>精确
                           	</label>
                           	<label class="radio-inline">
                           		<input type="radio" name="searchType" value="0"/>模糊
                           	</label>
                        </div>
                    </form>
                </div>
            </div>
        </div>
		<!-- 数据表格 -->
        <div class="row">
            <div class="col-xs-12">
            	<div id="table-subject-toolbar">
            		<div class="btn-group btn-group-sm">
	                    <button id="addSubject" class="btn btn-info btn-sm no-border" 
	                    onclick="goAdd('新增专题', 'mnui/sub/sub/add', 'table-subject');">
	                        <i class="ace-icon fa fa-plus bigger-110"></i>新增
	                    </button>
	                    <button id="editSubject" class="btn btn-success btn-sm no-border"
	                    onclick="goUpdate('编辑专题', 'mnui/sub/sub/edit', 'table-subject');">
	                        <i class="ace-icon fa fa-pencil-square-o bigger-110"></i>编辑
	                    </button>
	                    <button id="delSubject" class="btn btn-danger btn-sm no-border"
	                    onclick="doDels('mnui/sub/sub/deletes', 'table-subject');">
	                        <i class="ace-icon fa fa-trash-o bigger-110"></i>删除
	                    </button>
	                    <button id="enable" class="btn btn-primary btn-sm no-border"
	                    onclick="enable('0');">
	                        <i class="ace-icon fa fa-check-square-o bigger-110"></i>启用
	                    </button>
	                    <button id="disable" class="btn btn-warning btn-sm no-border"
	                    onclick="enable('1');">
	                        <i class="ace-icon fa fa-square-o bigger-110"></i>停用
	                    </button>
	                    <button id="creHtmls" class="btn btn-info btn-sm no-border" 
	                    onclick="creHtmls();">
	                        <i class="ace-icon fa fa-plus bigger-110"></i>生成静态页面
	                    </button>
                    </div>
                </div>
            	<table id="table-subject" 
            			data-toolbar="#table-subject-toolbar" 
            			data-sort-name="uuid" 
            			data-sort-order="asc"
            			data-show-columns="true"
            			data-id-field="uuid">
            		 <thead>
                        <tr>
                            <th data-field="state" data-checkbox="true"></th>
                            <th data-field="name" data-align="left" data-sortable="true">名称</th>
                            <th data-field="url" data-align="left" data-sortable="false">静态页面访问url</th>
                            <th data-width="100" data-field="subject_code" data-align="center" data-sortable="false">项目编码</th>
                            <th data-width="100" data-field="pages" data-align="center" data-sortable="false">每页个数</th>
                         	<th data-width="300" data-field="create_time" data-align="left" data-sortable="false">创建时间</th>
                            <th data-width="80" data-field="url" data-align="center" data-sortable="false" data-formatter="_creHtml">静态页面</th>
                            <th data-width="80" data-field="type" data-align="center" data-sortable="false" data-formatter="enableF">启用状态</th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
	</div>
</div>

<script type="text/javascript">
//生成静态页面
function creHtmls(){
	var selections = $('#table-subject').bootstrapTable("getSelections");
	if (selections !== undefined && selections !== null) {
		if (selections.length > 0) {
			var ids = "";
			for (var i = 0; i < selections.length; i++) {
				ids += selections[i].uuid;
				if (i < selections.length - 1) {
					ids += ",";
				}
			}
			var isOk = confirm("您确定要生成当前选中的数据记录的静态页面吗?");
			var params = {};
			params['ids'] = ids;
			if (isOk) {
				$.ajax({
					type : "POST",
					url : "mnui/sub/sub/createStaticHtml",
					data : params,
					success : function(data) {
						if (data.status == "OK") {
							$("#table-subject").bootstrapTable('refresh');
							TipMsg.success(data.message, 0);
						} else {
							TipMsg.error(data.message, 0);
						}
					}
				});
			}
		} else {
			TipMsg.error("请至少选择一条数据记录.", 0);
		}
	} else {
		TipMsg.error("没有可操作的数据记录.", 0);
	}
}
//对启用/停用 一列进行整理
function enableF(value, row, index) {
	var val = parseInt(value)
	switch (val) {
	case 0:
		return "<font style=\"color:blue;\">已启用</font>";
	case 1: 
		return "<font style=\"color:red;\">已停用</font>";
	default:
		return val;
	}
}
//对 静态页面 一列进行整理
function _creHtml(value, row, index) {
	var val = "";
	if(value != null && value != ""){
		val = "<font style=\"color:blue;\">已生成</font>";
	}else{
		val = "<font style=\"color:red;\">未生成</font>";
	}
	return val;
}
//ajax设置批量启用/停用
function enable(type) {
	var selections = $('#table-subject').bootstrapTable("getSelections");
	if (selections !== undefined && selections !== null) {
		if (selections.length > 0) {
			var ids = "";
			for (var i = 0; i < selections.length; i++) {
				ids += selections[i].uuid;
				if (i < selections.length - 1) {
					ids += ",";
				}
			}

			var _msg = "";
			if(type == '0'){
				_msg = "您确定要启用当前选中的数据记录吗?";
			}
			if(type == '1'){
				_msg = "您确定要停用当前选中的数据记录吗?";
			}
			var isOk = confirm(_msg);
			var params = {};
			params['ids'] = ids;
			params['type'] = type;
			if (isOk) {
				$.ajax({
					type : "POST",
					url : "mnui/sub/sub/enableAJax",
					data : params,
					success : function(data) {
						if (data.status == "OK") {
							$("#table-subject").bootstrapTable('refresh');
							TipMsg.success(data.message, 0);
						} else {
							TipMsg.error(data.message, 0);
						}
					}
				});
			}
		} else {
			TipMsg.error("请至少选择一条数据记录.", 0);
		}
	} else {
		TipMsg.error("没有可操作的数据记录.", 0);
	}
}

$(document).ready(function(){
	initTableList('table-subject','mnui/sub/sub/dataGrid', 'table-subject-search', 'btn-subject-search');
});
</script>
